import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public enum Color {
    RED(0,"RED"),
    BLUE(1,"BLUE"),
    BLACK(2,"BLACK"),
    WHITE(3,"WHITE");
    int ordinal;
    String color;
    private Color(int ordinal, String color){//构造方法必须是私有的！！！
        this.color = color;
        this.ordinal = ordinal;
    }

    public static void main1(String[] args) {
        Color color1 = Color.BLUE;
        switch (color1){
            case RED:
                System.out.println("red");
                break;
            case BLUE:
                System.out.println("blue");
                break;
            case BLACK:
                System.out.println("black");
                break;
            case WHITE:
                System.out.println("white");
                break;
        }
    }
    public static void main(String[] args) {
        Color[] d = Color.values();
        for(Color x : d){
            System.out.println(x + " " + x.ordinal());
        }
        Color a = Color.valueOf("RED");
        System.out.println(a);
        System.out.println(RED.compareTo(BLACK));
    }
}
class Demo{
    public static void main(String[] args) {
        Class<?> a;
        try {
            a = Class.forName("Color");
            Constructor<?> constructor
                    = a.getDeclaredConstructor(String.class, int.class, int.class, String.class);//修改1
            constructor.setAccessible(true);
            Color color = (Color) constructor.newInstance("lili",666,5,"YELLOW");//修改2
            System.out.println(color);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}